<%--
  Created by IntelliJ IDEA.
  User: 23867
  Date: 2020/10/4
  Time: 22:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>增加杆塔信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script type="text/javascript"src="../../js/jquery-3.4.1.js"></script>
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form" action="" id="myform">

    <div class="layui-inline" style="margin-top: 30px">
        <label class="layui-form-label" style="width: 90px;">所属路线：</label>
        <div class="layui-input-inline" style="width: 250px">
            <select name="line_number" id="line_number" lay-filter="xmFilter">
                <option value=""></option>
            </select>
        </div>
    </div>


    <div class="layui-form-item" style="margin-top: 20px">
        <div class="layui-inline" >
            <label class="layui-form-label" style="width: 90px;">杆塔编号：</label>
            <div class="layui-input-inline">
                <input type="text"  name="tower_name" lay-verify="required|tower_name" autocomplete="off" class="layui-input"style="width: 250px">
            </div>
        </div>
    </div>

    <div class="layui-form-item" pane="">
        <label class="layui-form-label" style="width: 90px;">启用状态：</label>
        <div class="layui-input-inline" style="width: 250px">
            <select name="defect_grade" lay-verify="required" lay-filter="xmFilter">
                <option value=""></option>
                <option value="启用">启用</option>
                <option value="禁用">禁用</option>
            </select>
        </div>
    </div>

    <div>
        <button type="button" class="layui-btn layui-btn-normal" style="margin-left: 90px;" lay-filter="sure" lay-submit="">确定</button>
        <button type="button" class="layui-btn layui-btn-normal" id="banck" style="margin-left: 50px">返回</button>
    </div>

</form>
<script src="../../layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    //返回按钮点击事件
    $(document).on('click',"#banck",function () {
        parent.layer.close(parent.layer.index);
    })
</script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //动态给搜索线路框select中option添加线路内容
        $.ajax({
            url:"/showSelectLine.do",
            data:{},
            dataType:"json",
            type: 'post',
            success: function (data) {
//                   console.log(data);//下面会提到这个data是什么值
                //使用循环遍历，给下拉列表赋值
                $.each(data.data, function (index, value) {
                    $('#line_number').append(new Option(value.line_number,value.line_id));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(sure)', function(data){
            $.ajax({
                url:"/addtower.do",
                type:"post",
                data:JSON.stringify(data.field),
                dataType:"json",
                success:function (result) {
                    if (result.code == 200){
                        layer.msg("添加成功,3秒后关闭当前以页...",{icon:1,time:3000,shade:0.4},function() {
                            parent.layer.close(parent.layer.index);
                        });
                    }else if (result.code == 500){
                        alert(result.message);
                    }else if (result.code == 405){
                        layer.msg(result.msg,{icon:5});
                    }
                }
            });
            return false;
        });


        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
</script>

</body>
</html>
